package com.xinsoft.controller.basic;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysLogExportParam;
import com.xinsoft.entity.dto.SysLogParam;
import com.xinsoft.service.SysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName SysLogController
 * @Description 日志管理控制层
 * @Author lijie
 * @Date 2023年5月18日10:41:59
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/log")
@Api(value = "SysLogController", tags = {"日志管理控制层"})
@Slf4j
public class SysLogController {
	@Autowired
	private SysOperLogService logService;

	/**
	 * @Author Li9527
	 * @Description 日志分页
	 * @Date 2023/5/18 10:51
	 * @params   param
	 * @return com.xinsoft.common.Response<?>
	 **/
	@PostMapping("/pageList")
	public Response<?> pageList(@Valid @RequestBody SysLogParam param) {
		return Response.succeed(logService.findPageListByParam(param));
	}


	/**
	 * @Author Li9527
	 * @Description 删除日志
	 * @Date 2023年5月19日09:01:24
	 * @params   ids
	 * @return com.xinsoft.common.Response<?>
	 **/
	@ApiOperation("删除日志")
	@PostMapping("/del")
	public Response<?> del(@RequestBody List<Integer> ids) {
		logService.removeByIds(ids);
		return Response.succeed();
	}

	/**
	 * @Author Li9527
	 * @Description TODO
	 * @Date 2023/5/30 9:04
	 * @params   pageParam response
	 * @return void
	 **/
	@ApiOperation(value = "根据条件导出系统日志信息")
	@PostMapping("/export")
	public void exportLogList(@RequestBody SysLogExportParam param, HttpServletResponse response) {
		try {
			logService.exportLogList(param,response);
		} catch (Exception e) {
			log.info("导出失败:" + e.getMessage());
		}
	}


}
